package com.share.core.jdbc.factory;

import com.share.core.type.ShardingType;
import com.share.core.jdbc.config.*;

import javax.sql.DataSource;
import java.sql.SQLException;

/**
 * @author caifan
 * @created 2021/8/11
 * description:
 */
public final class RangeDataSourceFactory {
    public static DataSource newInstance(final ShardingType shardingType) throws SQLException {
        switch (shardingType) {
            case SHARDING_DATABASES:
                return new ShardingDatabasesConfigurationRange().getDataSource();
            case SHARDING_TABLES:
                return new ShardingTablesConfigurationRange().getDataSource();
            case SHARDING_DATABASES_AND_TABLES:
                return new ShardingDatabasesAndTablesConfigurationRange().getDataSource();
            case READWRITE_SPLITTING:
                return new ReadwriteSplittingConfiguration().getDataSource();
            case SHARDING_READWRITE_SPLITTING:
                return new ShardingReadwriteSplittingConfigurationRange().getDataSource();
            default:
                throw new UnsupportedOperationException(shardingType.name());
        }
    }
}
